package behavior.command;

/**
 * @author lzp
 * @Date:2023/2/27
 * @description: 命令模式测试类
 */
public class CommandDemo {

	public static void main(String[] args) {
		// 不使用命令方式的调用方法
		TextEditor editor1 = new TextEditor();
		editor1.add("Command pattern in text editor.\n");
		editor1.copy();
		editor1.paste();
		System.out.println(editor1.getState());

		// 使用命令模式的测试DEMO    目的是把调用命令和执行命令分开，具体执行过程中还可以做一些历史记录等操作
		TextEditor editor2 = new TextEditor();
		editor2.add("Command pattern in text editor.\n");
		// 执行一个CopyCommand:
		Command copy = new CopyCommand(editor2);
		copy.execute();
		editor2.add("----\n");
		// 执行一个PasteCommand:
		Command paste = new PasteCommand(editor2);
		paste.execute();
		System.out.println(editor2.getState());
	}

}
